//package util;
//
//import java.io.ByteArrayOutputStream;
//import java.sql.Connection;
//import java.sql.DriverManager;
//import java.sql.ResultSet;
//import java.util.HashMap;
//import javax.faces.application.FacesMessage;
//import javax.faces.context.FacesContext;
//import javax.servlet.ServletContext;
//import javax.servlet.ServletOutputStream;
//import javax.servlet.http.HttpServletResponse;
//import net.sf.jasperreports.engine.JRExporterParameter;
//import net.sf.jasperreports.engine.JRResultSetDataSource;
//import net.sf.jasperreports.engine.JasperFillManager;
//import net.sf.jasperreports.engine.JasperPrint;
//import net.sf.jasperreports.engine.export.JRPdfExporter;
//
///**
// *
// * @author gilberto.costa 10/05/2012 09:03
// */
//public class Relatorio {
//
//    public static Connection getConnection() {
//        try {
//            Class.forName("org.postgresql.Driver");
//            String url = "jdbc:postgresql://174.142.135.100:5432/ContasPagarReceber";
//            Connection con = DriverManager.getConnection(url, "contas", "postgres");
//            return con;
//        } catch (Exception e) {
//            return null;
//        }
//    }
//
//    public static String CaminhoPathJasper() {
//        FacesContext facesContext = FacesContext.getCurrentInstance();
//        ServletContext scontext = (ServletContext) facesContext.getExternalContext().getContext();
//        String caminho = scontext.getRealPath("/jasper");
//        return caminho;
//    }
//
//    public static void PDF(String nomeJasper, ResultSet result,HashMap parameters) {
//        try {
//            JasperPrint jasperPrint = JasperFillManager.fillReport(CaminhoPathJasper() + "/" + nomeJasper, parameters, new JRResultSetDataSource(result));
//            ByteArrayOutputStream baos = new ByteArrayOutputStream();
//            JRPdfExporter exporter = new JRPdfExporter();
//            exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
//            exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
//            exporter.exportReport();
//            byte[] bytes = baos.toByteArray();
//            if (bytes != null && bytes.length > 0) {
//                FacesContext facesContext = FacesContext.getCurrentInstance();
//                facesContext.responseComplete();
//                HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
//                response.setContentType("application/pdf");
//                response.setHeader("Content-disposition", "inline; filename=\"" + nomeJasper + ".pdf\"");
//                response.setContentLength(bytes.length);
//                ServletOutputStream outputStream = response.getOutputStream();
//                outputStream.write(bytes, 0, bytes.length);
//                outputStream.flush();
//                outputStream.close();
//            }
//        } catch (Exception e) {
//            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro ao gerar o relat�rio: " + e, "Mensagem"));
//        }
//    }
//}
